package im.starchat.chat.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;

import java.util.ArrayList;

import im.starchat.chat.R;

public class ClassCenterTabTypeAdapter extends BaseAdapter {

	private ArrayList<String> mTitles;
	private Context mContext;
	private LayoutInflater mInflater;
	private TextView txtContentTitle;
	private View view, Courser;
	private int selectIndex = 0;
	private RelativeLayout lay;

	public ClassCenterTabTypeAdapter(Context context,
									 ArrayList<String> titles) {
		this.mContext = context;
		this.mTitles = titles;
		this.mInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return mTitles.size();
	}

	@Override
	public Object getItem(int position) {
		return mTitles.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("ResourceAsColor")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		convertView = mInflater.inflate(R.layout.item_horizontal_list, null);
		txtContentTitle = (TextView) convertView
				.findViewById(R.id.txtContentTitle);
//		view = (View) convertView.findViewById(R.id.view);
		Courser = (View) convertView.findViewById(R.id.Courser);
		lay = (RelativeLayout) convertView.findViewById(R.id.lay);
		WindowManager wm = (WindowManager) mContext
				.getSystemService(Context.WINDOW_SERVICE);
		int width = wm.getDefaultDisplay().getWidth() / 3;
		// LayoutParams lpCourser = Courser.getLayoutParams();
		LayoutParams lpParams = (LayoutParams) lay.getLayoutParams();
		// lpCourser.width = width;
		lpParams.width = width;
		txtContentTitle.setText(mTitles.get(position));

		if (selectIndex == position) {
			txtContentTitle.setTextColor(mContext.getResources().getColor(
					R.color.color_text_5));
			Courser.setBackgroundResource(R.color.color_text_5);
		}

//		if (position == (mTitles.size() - 1)) {
//			view.setVisibility(View.GONE);
//		}
		return convertView;
	}

	public void setSelectIndex(int i) {
		selectIndex = i;
	}
}
